package kr.ac.ml.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ac.kr.ml.dao.UserDao;
import ac.kr.ml.vo.UserVo;
import kr.ac.ml.mvc.Action;
import kr.ac.ml.mvc.HttpUtil;

public class LoginAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		System.out.println("loginAction");

		String key = request.getParameter("key");				
		
		UserDao dao = new UserDao();
		
		UserVo vo = dao.getUser(key);
		
		if(vo!=null){
			HttpSession session = request.getSession(true);//없으면 말들고 있면 보내라
			session.setAttribute("authUser", vo);
			HttpUtil.redirect(request, response, "/medialog/main?a=main&key="+vo.getKey());
		}else{
			HttpUtil.redirect(request, response, "/medialog/main");
		}
		
	}

}
